diff options
Diffstat (limited to 'src/routes/(app)/invoice/[hash]/+layout.server.js')
| -rw-r--r-- | src/routes/(app)/invoice/[hash]/+layout.server.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/routes/(app)/invoice/[hash]/+layout.server.js b/src/routes/(app)/invoice/[hash]/+layout.server.js new file mode 100644 index 00000000..61a479ab --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+layout.server.js @@ -0,0 +1,19 @@ +import Qr from 'qrcode-base64'; +import { get } from '$lib/utils'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ depends, params, url }) { + depends('app:invoice'); + + let { hash } = params; + let invoice = await get(`/invoice?hash=${hash}`); + let { amount, received } = invoice; + amount = parseInt(amount); + + let paid = (!amount && received) || (amount > 0 && received >= amount); + if (paid && !url.pathname.endsWith('paid')) throw redirect(307, `/invoice/${hash}/paid`); + + let sm = Qr.drawImg(invoice.text, { size: 300 }); + + return { hash, invoice, sm, lg: sm }; +} |
